/**
 * 安卓白金英雄坛制作组 <br>
 * 文件名：GmudWindow.java <br>
 * 创建时间：2013-6-30 下午7:52:01 <br>
 * 所属项目：GmudEX <br>
 * @author 12548 <br>
 */
package lostland.gmud.exv2.ui.core;

import android.graphics.Rect;

import lostland.gmud.exv2.Game;
import lostland.gmud.exv2.Gmud;
import lostland.gmud.exv2.blgframework.IGraphics;

/**
 * 类名：GmudWindow <br>
 * 说明：在屏幕显示的窗口类的基类。
 *
 * @author 12548
 */
public abstract class GmudWindow {

	protected Rect rect;
	public int x;
	public int y;
	public int width;
	public int height;

	protected boolean bordered = true;


	/**
	 * @return bordered
	 */
	public boolean isBordered() {
		return bordered;
	}


	/**
	 * @param bordered 要设置的 bordered
	 */
	public void setBordered(boolean bordered) {
		this.bordered = bordered;
	}


	/**
	 * @param instance 游戏对象
	 * @param x        左上角顶点x坐标
	 * @param y        左上角顶点y坐标
	 * @param width    宽度
	 * @param height   高度
	 */
	public GmudWindow(int x, int y, int width, int height) {
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
		this.rect = new Rect(x, y, x + width, y + height);
	}


	public boolean inBound(int x, int y) {
		return rect.contains(x, y);
	}

	protected void drawBackground() {
		IGraphics g = Game.getInstance().getGraphics();
		if (this.bordered) {
			g.drawRect(x, y, width, height, 0);
			g.drawRect(x + 1, y + 1, width - 2, height - 2, Gmud.getBgColor());
		} else {
			g.drawRect(x, y, width, height, Gmud.getBgColor());
		}
	}

	public void resize() {
		this.rect = new Rect(x, y, x + width, y + height);
	}

	abstract public void draw();

}
